package com.gulimall.cart.vo;

import java.math.BigDecimal;
import java.util.List;


public class Cart {

    List<CartItem> items;
    private Integer countNum;   //商品数量
    private Integer countType;  //商品类型数量
    private BigDecimal totalAmount; //商品总价
    private BigDecimal reduce;  //减免价格

    public Cart() {

    }

    public Cart(List<CartItem> items, Integer countNum, Integer countType, BigDecimal totalAmount, BigDecimal reduce) {
        this.items = items;
        this.countNum = countNum;
        this.countType = countType;
        this.totalAmount = totalAmount;
        this.reduce = reduce;
    }

    /**
     * 获取
     * @return items
     */
    public List<CartItem> getItems() {
        return items;
    }

    /**
     * 设置
     * @param items
     */
    public void setItems(List<CartItem> items) {
        this.items = items;
    }

    /**
     * 获取商品总量
     * @return countNum
     */
    public Integer getCountNum() {
        int count = 0;
        if (items != null && items.size() > 0) {
            for (CartItem item : items) {
                count += item.getCount();
            }
        }
        return count;
    }

    /**
     * 设置
     * @param countNum
     */
    public void setCountNum(Integer countNum) {
        this.countNum = countNum;
    }

    /**
     * 获取商品类型数量
     * @return countType
     */
    public Integer getCountType() {
        int countType = 0;
        if (items != null && items.size() > 0) {
            for (CartItem item : items) {
                countType += 1;
            }
        }
        return countType;
    }

    /**
     * 设置
     * @param countType
     */
    public void setCountType(Integer countType) {
        this.countType = countType;
    }

    /**
     * 计算总价格
     * @return totalAmount
     */
    public BigDecimal getTotalAmount() {
        BigDecimal amount = new BigDecimal(0);
        //计算购物项总价
        if (items != null && items.size() > 0) {
            for (CartItem item : items) {
                BigDecimal totalPrice = item.getTotalPrice();
                if (item.getCheck()) {
                    amount = amount.add(totalPrice);
                }
            }
        }
        //减去优惠总价
        return amount.subtract(getReduce() == null ? new BigDecimal(0) : getReduce());
    }

    /**
     * 设置
     * @param totalAmount
     */
    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }

    /**
     * 获取
     * @return reduce
     */
    public BigDecimal getReduce() {
        return reduce;
    }

    /**
     * 设置
     * @param reduce
     */
    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }

    public String toString() {
        return "Cart{items = " + items + ", countNum = " + countNum + ", countType = " + countType + ", totalAmount = " + totalAmount + ", reduce = " + reduce + "}";
    }
}
